import cv2


def splitFrames(videoFileName):
    cap = cv2.VideoCapture(videoFileName)  # 打开视频文件
    num = 0
    while True:
        # success 表示是否成功，data是当前帧的图像数据；.read读取一帧图像，移动到下一帧
        success, img = cap.read()
        if not success:
            break
        img_new = img
        width = int(img_new.shape[1])
        height = int(img_new.shape[0])
        dim = (width, height)
        img_new = cv2.resize(img_new, dim, interpolation=cv2.INTER_AREA)

        cv2.imwrite('../' + str(num) + ".jpg", img_new)
        print(num)
        num = num + 1

    cap.release()


splitFrames('video.mp4')
